﻿namespace HEFramework
{
    public static class ResourcesComponentSystem
    {
        [EntitySystem]
        public class ResourcesComponentAwakeSystem : AwakeSystem<ResourcesComponent>
        {
            protected override void Awake(ResourcesComponent _self)
            {
                _self.Assets = AssetLoader.Instance.GetAssets();
            }
        }

        [EntitySystem]
        public class ResourcesComponentDestroySystem : DestroySystem<ResourcesComponent>
        {
            protected override void Destroy(ResourcesComponent _self)
            {
                _self.Assets.Dispose();
            }
        }


        /// <summary>
        /// 下载并更新AB文件 
        /// </summary>
        /// <param name="_self"></param>
        /// <returns></returns>
        public static async HETask<ResourcesComponent> UpdateAssetBundleFile(this ResourcesComponent _self)
        {
            await AssetBundleDownloader.Instance.UpdateFile();
            return _self;
        }

        /// <summary>
        /// 加载AB依赖
        /// </summary>
        /// <param name="_self"></param>
        /// <returns></returns>
        public static ResourcesComponent LoadAssetBundleDependenciesSyn(this ResourcesComponent _self)
        {
            AssetBundleLoader.Instance.LoadDependenciesSyn();
            return _self;
        }
    }
}